Skip to content

fix: gok vm: use cpu:host instead of named variants#100

Open
damdo wants to merge 1 commit into
gokrazy:mainfrom
damdo:fix-gok-vm-for-qemu-10
Open

fix: gok vm: use cpu:host instead of named variants#100
damdo wants to merge 1 commit into
gokrazy:mainfrom
damdo:fix-gok-vm-for-qemu-10

Conversation

@damdo

@damdo damdo commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

I was seeing this error when running gok vm from macos.

qemu-system-aarch64: Invalid CPU model: cortex-a72

Which is due this series of qemu changes: https://patchew.org/QEMU/20231129042012.277831-1-gshan@redhat.com/#:~:text=157%20deletions(%2D)-,%5BPATCH%20v8%200%2F9%5D%20Unified%20CPU%20type%20check,been%20queued%20to%20the%20branch.

This is what the docs state:

A note about CPU models and KVM
Named CPU models generally do not work with KVM. There are a few cases that do work, e.g. using the named CPU model cortex-a57 with KVM on a seattle host, but mostly if KVM is enabled the host CPU type must be used. This means the guest is provided all the same CPU features as the host CPU type has. And, for this reason, the host CPU type should enable all CPU features that the host has by default. Indeed it’s even a bit strange to allow disabling CPU features that the host has when using the host CPU type, but in the absence of CPU models it’s the best we can do if we want to launch guests without all the host’s CPU features enabled.

This validation was ignored in qemu 9 and made strict in 10

ref: https://www.qemu.org/docs/master/system/arm/cpu-features.html

I was seeing this error when running `gok vm` from macos.
```
qemu-system-aarch64: Invalid CPU model: cortex-a72
```
Which is due this series of qemu changes: https://patchew.org/QEMU/20231129042012.277831-1-gshan@redhat.com/#:~:text=157%20deletions(%2D)-,%5BPATCH%20v8%200%2F9%5D%20Unified%20CPU%20type%20check,been%20queued%20to%20the%20branch.

This is what the docs state:

A note about CPU models and KVM
Named CPU models generally do not work with KVM. There are a few cases that do work, e.g. using the named CPU model cortex-a57 with KVM on a seattle host, but mostly if KVM is enabled the host CPU type must be used. This means the guest is provided all the same CPU features as the host CPU type has. And, for this reason, the host CPU type should enable all CPU features that the host has by default. Indeed it’s even a bit strange to allow disabling CPU features that the host has when using the host CPU type, but in the absence of CPU models it’s the best we can do if we want to launch guests without all the host’s CPU features enabled.

This validation was ignored in qemu 9 and made strict in 10

ref: https://www.qemu.org/docs/master/system/arm/cpu-features.html
@damdo

damdo commented Apr 21, 2026

Copy link
Copy Markdown
Contributor Author

cc. @stapelberg

@damdo

damdo commented Apr 23, 2026

Copy link
Copy Markdown
Contributor Author

Closing and reopening to kick off testing again

@damdo damdo closed this Apr 23, 2026
@damdo damdo reopened this Apr 23, 2026
@damdo damdo changed the title gok vm: use cpu:host instead of named variants fix: gok vm: use cpu:host instead of named variants May 27, 2026
@damdo

damdo commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

I'm surprised others haven't seen this 😅
Maybe I'm the only one running nix unstable's qemu 😬
Have you noticed this @stapelberg ?

@stapelberg

Copy link
Copy Markdown
Contributor

I'm surprised others haven't seen this 😅
Maybe I'm the only one running nix unstable's qemu 😬
Have you noticed this @stapelberg ?

I’m running qemu 10.2.2 from NixOS 26.05 (matches what’s in nixpkgs-unstable) and am not seeing this issue.

Are you running on an x86-64 host, too?

Comment thread internal/gok/vmrun.go
qemu.Args = append(qemu.Args,
"-machine", "virt,highmem=off",
"-cpu", "cortex-a72",
"-cpu", "host",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, -cpu=host does not work for me?

% qemu-system-aarch64 -name dr -boot order=d -drive file=/tmp/gokrazy-vm1161502338,format=raw -device i6300esb,id=watchdog0 -watchdog-action reset -smp 32 -device e1000,netdev=net0 -netdev user,id=net0,hostfwd=tcp::8080-:80,hostfwd=tcp::8022-:22 -m 1024 -machine virt,highmem=off -cpu cortex-a72 -bios /tmp/gokrazy-vm1861489883/arm64-QEMU_EFI.fd
^Cqemu: terminating on signal 2

% qemu-system-aarch64 -name dr -boot order=d -drive file=/tmp/gokrazy-vm1161502338,format=raw -device i6300esb,id=watchdog0 -watchdog-action reset -smp 32 -device e1000,netdev=net0 -netdev user,id=net0,hostfwd=tcp::8080-:80,hostfwd=tcp::8022-:22 -m 1024 -machine virt,highmem=off -cpu host -bios /tmp/gokrazy-vm1861489883/arm64-QEMU_EFI.fd      
qemu-system-aarch64: unable to find CPU model 'host'

@damdo

damdo commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Are you running on an x86-64 host, too?

Nope, running it on macOS's Darwin arm64

$ ./gok [...] vm run --graphic=false

...
2026/06/03 21:03:52
2026/06/03 21:03:52 running QEMU
[qemu-system-aarch64 -name gokrazy-dummy-arm64 -boot order=d -drive file=/var/folders/23/sd8wmjm93wl5895s_zk2kvfw0000gn/T/tmp.oNUBpyeOLw/gokrazy-vm1083429622,format=raw -device i6300esb,id=watchdog0 -watchdog-action reset -smp 12 -device e1000,netdev=net0 -netdev user,id=net0,hostfwd=tcp::8080-:80,hostfwd=tcp::8022-:22 -m 1024 -machine virt,highmem=off -cpu cortex-a72 -bios /var/folders/23/sd8wmjm93wl5895s_zk2kvfw0000gn/T/tmp.oNUBpyeOLw/gokrazy-vm394458893/arm64-QEMU_EFI.fd -accel hvf -nographic]
qemu-system-aarch64: Invalid CPU model: cortex-a72
The valid models are: cortex-a53, cortex-a57, host, max
2026/06/03 21:03:53 [qemu-system-aarch64 -name gokrazy-dummy-arm64 -boot order=d -drive file=/var/folders/23/sd8wmjm93wl5895s_zk2kvfw0000gn/T/tmp.oNUBpyeOLw/gokrazy-vm1083429622,format=raw -device i6300esb,id=watchdog0 -watchdog-action reset -smp 12 -device e1000,netdev=net0 -netdev user,id=net0,hostfwd=tcp::8080-:80,hostfwd=tcp::8022-:22 -m 1024 -machine virt,highmem=off -cpu cortex-a72 -bios /var/folders/23/sd8wmjm93wl5895s_zk2kvfw0000gn/T/tmp.oNUBpyeOLw/gokrazy-vm394458893/arm64-QEMU_EFI.fd -accel hvf -nographic]: exit status 1
make: *** [vm] Error 1

$ ./gok version
https://github.com/gokrazy/tools/commit/e4396f9c2c7d

$ uname -a
Darwin mac 24.6.0 Darwin Kernel Version 24.6.0: Tue Apr 21 20:16:56 PDT 2026; root:xnu 11417.140.69.710.16~1/RELEASE_ARM64_T6030 arm64 arm Darwin

$ qemu-system-aarch64 --cpu help
Available CPUs:
  a64fx
  arm1026
  arm1136
  arm1136-r2
  arm1176
  arm11mpcore
  arm926
  arm946
  cortex-a15
  cortex-a35
  cortex-a53
  cortex-a55
  cortex-a57
  cortex-a7
  cortex-a710
  cortex-a72 <------
  cortex-a76
  cortex-a78ae
  cortex-a8
  cortex-a9
  cortex-m0
  cortex-m3
  cortex-m33
  cortex-m4
  cortex-m55
  cortex-m7
  cortex-r5
  cortex-r52
  cortex-r5f
  host
  max
  neoverse-n1
  neoverse-n2
  neoverse-v1
  sa1100
  sa1110
  ti925t

$ qemu-system-aarch64 -version
QEMU emulator version 10.2.1
Copyright (c) 2003-2025 Fabrice Bellard and the QEMU Project developers

The error is quite strange because -cpu help shows cortex-a72 to be there, but then it doesn't detect it 🤔

Even running it manually doesn't work

$ qemu-system-aarch64 -name gokrazy-dummy-arm64 -boot order=d -drive file=/var/folders/23/sd8wmjm93wl5895s_zk2kvfw0000gn/T/tmp.oNUBpyeOLw/gokrazy-vm1083429622,format=raw -device i6300esb,id=watchdog0 -watchdog-action reset -smp 12 -device e1000,netdev=net0 -netdev
 user,id=net0,hostfwd=tcp::8080-:80,hostfwd=tcp::8022-:22 -m 1024 -machine virt,highmem=off -cpu cortex-a72 -bios /var/folders/23/sd8wmjm93wl5895s_zk2kvfw0000gn/T/tmp.oNUBpyeOLw/gokrazy-vm394458893/arm64-QEMU_EFI.fd -accel hvf -nographic
qemu-system-aarch64: Invalid CPU model: cortex-a72
The valid models are: cortex-a53, cortex-a57, host, max

@damdo

damdo commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

According to Gemini this might be a macOS only issue..

Why the Discrepancy?
--cpu help shows the Software Emulator (TCG) capabilities: When you ask QEMU for help, it lists every single ARM CPU architecture it is capable of emulating purely in software using its Tiny Code Generator (TCG). cortex-a72 is on that list because QEMU knows how to mimic it via software translation.
-accel hvf enforces Hardware Virtualization constraints: The moment gok appends -accel hvf, QEMU stops trying to emulate an ARM core in software. Instead, it hooks into macOS's native Hypervisor.framework (HVF) to run instructions directly on your Apple Silicon physical hardware.
Because you are passing instructions directly to your actual Mac CPU, you cannot pretend the core is a Raspberry Pi-style cortex-a72. The hypervisor strictly restricts the allowed -cpu targets to profiles compatible with your actual silicon. As your error message noted, under HVF, your choices drop down to: cortex-a53, cortex-a57, host, max.
Since gok automatically combines -accel hvf (because it sees you are on an arm64 Mac) with -cpu cortex-a72, it creates a command that QEMU rejects.

We could potentially use host on mac and keep cortex-a72 on linux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants